# 作者: YYJ
# 2025年07月12日13时33分10秒
# 2486249622@qq.com

from multiprocessing import Manager, Pool
import time, os, random

def reader(q):
    print(f"reader 启动{os.getpid()}, 父进程为{os.getppid()}")
    for i in range(q.qsize()):
        print("get %s from queue" % q.get(True))

def writer(q):
    print(f"writer 启动{os.getpid()}, 父进程为{os.getppid()}")
    for i in "wangdao":
        q.put(i)
    time.sleep(2)

if __name__ == '__main__':
    print(f"主进程启动{os.getpid()}")
    q = Manager().Queue()
    po = Pool()
    po.apply_async(writer, (q,))
    time.sleep(1)
    po.apply_async(reader, (q,))
    po.close()
    po.join()
    print(f"主进程结束{os.getpid()}")
